package com.jn.gsondemo.views;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.jn.geson_demo.R;


public class MainActivity extends AppCompatActivity {

    private NavController navController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 获取NavHostFragment
        NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
        if (navHostFragment != null) {
            // 获取NavController
            navController = navHostFragment.getNavController();
        } else {
            throw new IllegalStateException("NavHostFragment not found");
        }

        // 初始化FloatingActionButtons并设置点击监听器
        FloatingActionButton fabBook = findViewById(R.id.fab_book);
        FloatingActionButton fabOlympic = findViewById(R.id.fab_olympic);
        FloatingActionButton fabHotSearch = findViewById(R.id.fab_hot_search);

        fabBook.setOnClickListener(v -> navController.navigate(R.id.bookDetailFragment));
        fabOlympic.setOnClickListener(v -> navController.navigate(R.id.olympicFragment));
        fabHotSearch.setOnClickListener(v -> navController.navigate(R.id.hotSearchFragment));
    }
}